package net.csdn.business.notify.api.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.csdn.business.notify.api.service.*;
import net.csdn.business.notify.common.model.dto.*;
import net.csdn.business.notify.common.model.query.NotifyAnnounceQuery;
import net.csdn.business.notify.common.model.query.NotifyPrivateLetterQuery;
import net.csdn.business.notify.common.model.query.NotifyRemindRecordQuery;
import net.csdn.business.notify.common.model.vo.*;
import net.csdn.business.notify.common.enums.ProcessTypeEnum;
import net.csdn.business.notify.common.pipeline.param.SendRemindParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 通知中心
 * 
 * @author ruoyi
 * @date 2023-11-27
 */
@RestController
@RequestMapping("/api/v1/notify")
public class NotifyController
{

    @Autowired
    private INotifyService notifyService;


    @Autowired
    private INotifyPrivateLetterService notifyPrivateLetterService;

    @Autowired
    private INotifyRemindRecordService notifyRemindRecordService;

    @Autowired
    private INotifyAnnounceService notifyAnnounceService;

    @Autowired
    private INotifyUserSettingService notifyUserSettingService;
    @Autowired
    private ISendService sendService;


    /**
     * @ClassName NotifyController
     * @Description 发送系统通知接口
     * @Author zhangyl
     * @Date 2023/12/5 15:33
     */
   @PostMapping("")
    public NotifyResponseVO sendNotify(@RequestBody @Validated SendNotifyDTO params)
    {
        SendRemindParam sendRemindParam=new SendRemindParam();
        sendRemindParam.setBatchNum(params.getBatchNum());
        sendRemindParam.setBusCode(params.getBusCode());
        sendRemindParam.setSender(params.getSender());
        sendRemindParam.setReceiver(params.getReceiver());
        sendRemindParam.setVariables(params.getVariables());
        sendRemindParam.setUrl(params.getUrl());
        sendRemindParam.setNameSpace(params.getNameSpace());
        sendRemindParam.setTargetId(params.getTargetId());
        return sendService.sendRemind(ProcessTypeEnum.SEND_REMIND_NOTIFY.getCode(),sendRemindParam);
    }


    /**
     * @Author zhangyl
     * @Description 直接通过账号发送通知
     * @Date 14:10 2023/12/20
     * @Param
     * @return
     **/
    @PostMapping("/direct")
    public NotifyResponseVO sendNotifyDirect(@RequestBody @Validated SendNotifyDTO params)
    {
        SendRemindParam sendRemindParam=new SendRemindParam();
        sendRemindParam.setBatchNum(params.getBatchNum());
        sendRemindParam.setBusCode(params.getBusCode());
        sendRemindParam.setSender(params.getSender());
        sendRemindParam.setReceiver(params.getReceiver());
        sendRemindParam.setVariables(params.getVariables());
        /*sendRemindParam.setUrl(params.getUrl());
        sendRemindParam.setNameSpace(params.getNameSpace());
        sendRemindParam.setTargetId(params.getTargetId());*/
        return sendService.sendRemind(ProcessTypeEnum.SEND_DIRECT_NOTIFY.getCode(),sendRemindParam);
    }


    @GetMapping("/targetInfo")
    public List<NotifyTargetVO> getTargetInfo()
    {
        return notifyService.getTargetInfo();
    }

    /**
     * 前台用户查询未读消息数量
     */
    @GetMapping("/unread_count/{currUserId}")
    public UserUnReadConutVO getUnReadCount(@PathVariable("currUserId")String currUserId)
    {
        return notifyService.getUnReadCount(currUserId);
    }

    /**
     * 前台用户查询私信列表
     */
    @PostMapping("/list/private")
    public Page<UserPrivateLetterVO> userPrivatePage(@RequestBody NotifyPrivateLetterQuery query)
    {
        return notifyPrivateLetterService.userPrivatePage(query);
    }


    /**
     * 前台用户查询私信对话列表
     */
    @PostMapping("/list/dialogue")
    public Page<UserPrivateLetterVO> userDialoguePage(@RequestBody NotifyPrivateLetterQuery query)
    {
        return notifyPrivateLetterService.userDialoguePage(query);
    }


    /**
     * 前台用户查询系统通知列表
     */
    @PostMapping("/list/remind")
    public Page<UserRemindRecordVO> userRemindPage(@RequestBody NotifyRemindRecordQuery query)
    {
        return notifyRemindRecordService.userRemindPage(query);
    }


    /**
     * 前台用户查询系统公告列表
     */
    @PostMapping("/list/announce")
    public Page<UserAnnounceVO> userAnnouncePage(@RequestBody NotifyAnnounceQuery query)
    {
        return notifyAnnounceService.userAnnouncePage(query);
    }

    /**
     * 前台用户查询系统公告详情
     */
    @PostMapping("/announce/detail")
    public UserAnnounceVO userAnnounceDetail(@RequestBody NotifyAnnounceQuery query)
    {
        return notifyAnnounceService.userAnnounceDetail(query);
    }


    /**
     * 前台用户查询消息通知配置
     */
    @GetMapping("/setting/{currUserId}")
    public List<UserSettingVO>  getUserNotifySetting(@PathVariable("currUserId")String currUserId)
    {
        return notifyUserSettingService.getUserNotifySetting(currUserId);
    }


    /**
     * 前台用户更新消息通知配置
     */
    @PostMapping("/setting")
    public Integer userNotifySetting(@RequestBody @Validated UserNotifySetDTO params)
    {
        return notifyUserSettingService.userNotifySetting(params);
    }


    /**
     * 前台用户发送私信
     */
    @PostMapping("/private/message")
    public Integer userSendPrivateMsg(@RequestBody @Validated UserSendPrivateMsgDTO params) throws Exception
    {
        return notifyService.userSendPrivateMsg(params);
    }

    /**
     * 前台用户发送私信，查询是否能发送私信
     */
    @PostMapping("/private/enable")
    public boolean userSendPrivateEnable(@RequestBody @Validated UserSendPrivateEnableDTO params)
    {
        return notifyUserSettingService.userSendPrivateEnable(params);
    }

    /**
     * 前台用户标记通知或者私信为已读状态
     */
    @PostMapping("/mark")
    public void markNotify(@RequestBody @Validated MarkMessageDTO params)
    {
         notifyService.markNotify(params);
    }

    /**
     * 前台用户批量删除私信接口
     */
    @PostMapping("/private/batch_delete")
    public void batchDelete(@RequestBody @Validated BatchDeleteMessageDTO params)
    {
        notifyPrivateLetterService.batchDelete(params);
    }


}
